package org.ricks.common.conf;

import java.io.InputStream;
import java.util.Objects;
import java.util.Properties;

/**
 * @author chenwei
 * @Title:
 * @Package
 * @Description:
 * @date 2020/8/717:22
 */
public class LoadProperties extends AbstractLoadProperties {

    private LoadProperties() {
    }

    /**
     * singleton by static inner class
     */
    private static class LoadPropertiesHolder {
        private static LoadProperties loadProperties = new LoadProperties();
    }

    public static LoadProperties getInstance() {
        return LoadPropertiesHolder.loadProperties;
    }

    @Override
    public Object loadSources(InputStream inputStream) throws Exception {
        Properties properties = new Properties();
        if (Objects.isNull(inputStream))
            return null;
        properties.load(inputStream);
        inputStream.close();
        return convertToMap(properties);
    }

}
